import request from '@/utils/request'
import { timeFormat, dateDiff } from '@/utils/dateUtil'
const api = {}

let stat = { '-1': '已删除', 0: '下载中', 1: '等待生成文件', 2: '已完成' }

//报表导出记录表
api.getListquery = (pageNo, pageSize) => {
  let data = {}
  let p = request({
    url: `/log/downloadLog/getList/${pageNo}/${pageSize}`,
    method: 'get',
    data
  })
  p = p.then(res => {
    let page = res.data.page;
    page.list.forEach(e => {
      e.createTime = timeFormat(e.createTime)
      e.filename = e.filePath?.split('_')[1] ?? '无'  //文件名处理

      if (e.stat == 2 && dateDiff(new Date(), e.createTime) < 15) {  //15天内能下载
        e.show = true
      } else {
        e.shor = false
      }

      if (e.stat == 2) {
        e.stat = '<b style="color:green">' + stat[e.stat] + '</b>'
      } else {
        e.stat = stat[e.stat]
      }
    });
    return page;
  })
  return p


}

//报表下载
api.download = path => {
  request({
    url: `/report/admin/getDownloadPass?path=` + encodeURI(path),
    method: 'post'
  }).then(res => {
    window.open('/api/report/test/download?pass=' + res.data.pass)
  })
}

export default api